# C 目标可执行文件
C_TARGET = lib_test/test_lib

# Go 目标可执行文件
GO_TARGET = main

# C 源文件
C_SRCS = lib_test/test_lib.c

# Go 源文件
GO_SRCS = main.go

# 头文件路径
INCLUDE_DIRS = \
    -I$(INC_HITLS_PATH)/crypto \
    -I$(INC_HITLS_PATH)/bsl

# 库路径
LIB_DIR = $(LIB_HITLS)

# 库名称
LIBS = -lhitls_crypto -lhitls_bsl -lboundscheck

# C 编译器和链接器
CC = gcc

# C 编译选项
CFLAGS = $(INCLUDE_DIRS)

# C 链接选项
LDFLAGS = -L$(LIB_DIR) $(LIBS)

# Go 构建时的 CGO 标志
CGO_CFLAGS = $(CFLAGS)
CGO_LDFLAGS = $(LDFLAGS)

# 默认目标
default: go

# 构建 Go 程序
go: $(GO_SRCS)
	CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" go build -o $(GO_TARGET) $(GO_SRCS)

go_test:
	CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" go test ./hitls/crypto/...

# 构建 C 程序
test_lib: $(C_SRCS)
	$(CC) $(CFLAGS) $(C_SRCS) -o $(C_TARGET) $(LDFLAGS)

# 清理生成的文件
clean:
	rm -f $(C_TARGET) $(GO_TARGET)

# 帮助信息
help:
	@echo "Makefile Usage:"
	@echo "  make          - Build the Go program (alias for 'make go')."
	@echo "  make go       - Build the Go program."
	@echo "  make test_lib - Build the C program."
	@echo "  make clean    - Remove the generated executables."
	@echo "  make help     - Show this help message."